package com.intellagric.service.iftmonitor.Impl.ift_channel;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.dao.iftmonitor.ChannelDao;
import com.intellagric.mapper.IftChannelMapper;
import com.intellagric.module.iftmonitor.ChannelVo;
import com.intellagric.pojo.IftChannel;
import com.intellagric.pojo.IftChannelExample;
import com.intellagric.service.iftmonitor.ift_channel.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/20
 * @DESC： 通道服务实现
 */
@Service
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    private IftChannelMapper channelMapper;

    @Autowired
    private ChannelDao channelDao;

    /**
     * 添加通道信息
     * @Param channel
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addChannel(IftChannel channel) {
        if (channelMapper.insertSelective(channel) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除通道信息
     * @Param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteChannel(String id) {
        if (channelMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改通道信息
     * @Param channel
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editChannel(IftChannel channel) {
        if (channelMapper.updateByPrimaryKeySelective(channel) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询通道信息
     * @return Channel
     */
    @Override
    public IftChannel getChannelById(String id) {
        return channelMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询通道信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getChannelList() {
        IftChannelExample channelExample = new IftChannelExample();
        channelExample.createCriteria().andIdIsNotNull();
        List<IftChannel> channelList = channelMapper.selectByExample(channelExample);
        return LayuiDataGridResult.success().add(channelList,channelList.size());
    }

    /**
     * 多条件查询通道信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getChannelListByVo(ChannelVo channelVo) {
        List<IftChannel> channelList = channelDao.selectChannelListByVo(channelVo);
        return LayuiDataGridResult.success().add(channelList,channelList.size());
    }

    /**
     * 分页查询通道信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getChannelPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftChannelExample channelExample = new IftChannelExample();
        channelExample.createCriteria().andIdIsNotNull();
        List<IftChannel> channelList = channelMapper.selectByExample(channelExample);
        return LayuiDataGridResult.success().add(channelList,this.getChannelList().getCount());
    }
}
